import React, { Component } from 'react';
import { Provider } from 'react-redux';
import { BrowserRouter, Route, Switch } from 'react-router-dom'; 

import AuthRouter from './components/authRouter';
import Login from './pages/login';
import Register from './pages/register';
import BossInfo from './pages/bossinfo';
import Geniusinfo from './pages/geniusinfo';
import Dashboard from './components/dashboard';
import Chat from './components/chat';

import ErrorPage from './components/error'

import store from './store';

class App extends Component {
    constructor(props) {
        super(props);
        this.state = { hasError: false };
    }

    componentDidCatch(err, info) { //错误处理机制
        this.setState({ hasError: true });
    }

    render() {
        if (this.state.hasError) {
            return <ErrorPage />
        }
        return(
            <Provider store={store}>
                <BrowserRouter>
                    <div>
                        <AuthRouter></AuthRouter>
                        <Switch> 
                            <Route path="/login" component={Login}></Route>
                            <Route path="/register" component={Register}></Route>
                            <Route path="/chat/:user" component={Chat}></Route>
                            <Route path="/geniusinfo" component={Geniusinfo}></Route>
                            <Route path="/bossinfo" component={BossInfo}></Route>
                            <Route component={Dashboard}></Route>
                        </Switch>                      
                    </div>
                </BrowserRouter>
            </Provider>
        );
            
    }
}

export default App;
